#! /usr/bin/env node

const program  = require('commander');

const inquirer = require('inquirer');

const axios = require('axios');

// program
//     .version('1.0.0','-v,--version')
//     .option('-a,--add','add something')
//     .option('-u,--update','update something')
//     .option('-r,--remove','remove somthing')
//     .parse(process.argv) //格式化命令行参数

// if(program.add) console.log(' add somthing')
// if(program.update) console.log(' update something')
// if(program.remove) console.log(' remove something')

const promptList = [  //交互的问题
    {
        type: 'input',
        message: '请输入城市:',
        name: 'city'
    },
    // {
    //     type: 'password',
    //     message: '设置一个密码:',
    //     name: 'pwd'
    // }
];

let userlist = [
    // {
    //     username:'lili',
    //     pwd:123
    // },
    // {
    //     username:'zs',
    //     pwd:124
    // }
]

program
    .command('login')  //自定义命令
    .action(() => {     //执行的动作
        inquirer.prompt(promptList).then(answers => {
            console.log(answers); // 返回的结果 {name:'ss',pwd:122}
            // let isSuccess = userlist.some(item => {
            //     return item.username === answers.name && item.pwd === answers.pwd*1
            // })
            // if(isSuccess){
            //     console.log("登录成功")
            // }else{
            //     console.log("登录失败")
            // }

            axios.get('https://www.tianqiapi.com/api/',{params:{city:answers.city,appid:23035354,appsecret:'8YvlPNrz',version:'v9'}}).then(res => {
                console.log(res);
            })
        })
    }) 

program.parse(process.argv);